//////////////////////////////////////////////////////////////////////////////
//
//  File: buff.h
//  
//  Description:
//    This class helps to manage a buffer object that is basically an
//    malloc-ed area of memory managed by a void pointer.
//    
//  Status:  Completed.
//
//
#ifndef BUFF_H
#define BUFF_H

#include<fstream>

using namespace std;

#include "types.h"


string print_hex_form(u8 x);
string print_hex_form(u32 x);

class buff {

 public:
  buff();
  ~buff();
  bool add(const void* toAdd, int bytes);  // appends to the end of buff
  void clear();
  short size();
  void* getPtr();
  void setPacketID(u8 newID);    // set and get packetID
  u8 getPacketID();
  void setPacketSz(u16 newSz);
  unsigned short getPacketSz();
  bool package();   // get the buffer ready to be sent.
  bool strip();     // strip the header info off and leave just the data.
  bool extract(u8 &stuff);   // extract from the front of the buffer.
  bool extract(u16 &stuff);
  bool extract(u32 &stuff);
  bool extract(u64 &stuff);
  bool extract(string &stuff);
  bool extract(char *stuff);

  string print_buffer();

  void setStripped( const bool& stripped ); 
  bool stripped() const; // Returns if the buffer already stripped a packet.
 private:
  bool stripped_;

  u8* data;
  u16 sz;   // Number of bytes left in the buffer.
  u16 packetSz;  // Number of bytes left in buffer for the
                            //   current packet
  
  u8 packetID;
  u8 startByte;
};

#endif
